﻿using System;
using System.Data.Objects;
using System.Linq;
using NopSolutions.NopCommerce.BusinessLogic.Data;
using NopSolutions.NopCommerce.BusinessLogic.Model;
using System.Collections.Generic;

namespace NopSolutions.NopCommerce.BusinessLogic.Services
{
    public class ProductCompiledQueries
    {
        public static readonly Func<NopObjectContext, bool, IQueryable<Product>> ProductsDisplayedOnHomePage =
            CompiledQuery.Compile<NopObjectContext, bool, IQueryable<Product>>(
                    (ctx, showHidden) => from p in ctx.Products
                                         orderby p.Name
                                         where (showHidden || p.Published) &&
                                         !p.Deleted &&
                                         p.ShowOnHomePage
                                         select p
            );
    }
}
